var DOC = document,
    WIN = window,
    IsTouch = "ontouchstart" in WIN,
    UA = WIN.navigator.userAgent,
    IsAndroid = /Android|HTC/i.test(UA) || !! (WIN.navigator.platform + "").match(/Linux/i),
    IsIPad = !IsAndroid && /iPad/i.test(UA),
    IsIPhone = !IsAndroid && /iPod|iPhone/i.test(UA),
    IsIOS = IsIPad || IsIPhone,
    IsWindowsPhone = /Windows Phone/i.test(UA),
    IsIEMobile = /IEMobile/i.test(UA),
    IsIE = !! DOC.all,
    PixelRatio = parseFloat(WIN.devicePixelRatio) || 1,
    MAX_TOUCHMOVE_DISTANCE_FOR_CLICK = IsAndroid ? 10 : 6,
    START_EVENT = IsTouch ? "touchstart" : "mousedown",
    MOVE_EVENT = IsTouch ? "touchmove" : "mousemove",
    END_EVENT = IsTouch ? "touchend" : "mouseup",
    _hasGetElementsByClassName = DOC.getElementsByClassName,
    ScreenSizeCorrect = 1;
function getScrollTop() {
    return "pageYOffset" in window ? window.pageYOffset : "BackCompat" === document.compatMode && document.body.scrollTop || document.documentElement.scrollTop
}
var ImageLazyload = {
    time: null,
    hasEvent: !1,
    init: function(a) {
        clearTimeout(ImageLazyload.time);
        ImageLazyload.time = setTimeout(function() {
            ImageLazyload.lazyLoadImage(a)
        }, 100);
        ImageLazyload.hasEvent || (WIN.addEventListener("scroll", function() {
            clearTimeout(ImageLazyload.time);
            ImageLazyload.time = setTimeout(function() {
                ImageLazyload.lazyLoadImage()
            }, 100)
        }, !1), ImageLazyload.hasEvent = !0)
    },
    lazyLoadImage: function(a, c) {
        var b = document.querySelectorAll(".lazy"),
            e, d = b.length;
        for (e = 0; e < d; e++) a && "all" == a ? ImageLazyload.imageReplace(b[e]) : ImageLazyload.imageVisiable(b[e])
    },
    imageVisiable: function(a, c) {
        var b = a.getBoundingClientRect();
        c = $(a).parent();
        if (0 < b.top && 0 < WIN.innerHeight - b.top || 0 >= b.top && 0 <= b.bottom) c.hasClass("_loaded") || ImageLazyload.imageReplace(a)
    },
    imageReplace: function(a) {
        if (a) {
            var c = $(a).parent(),
                b;
            b || (b = $(a).attr("data-url").replace("{new}", ""));
            var e = new Image;
            e.src = b;
            e.onload = function() {
                $(a).attr("src", e.src);
                c.removeClass("_loaderror");
                c.addClass("_loaded");
                $(a).removeAttr("data-url")
            };
            e.onerror = function() {
                c.addClass("_loaderror")
            }
        }
    }
};

var BackgroundLazyload = {
    time: null,
    hasEvent: !1,
    init: function(a) {
        clearTimeout(BackgroundLazyload.time);
        BackgroundLazyload.time = setTimeout(function() {
            BackgroundLazyload.lazyLoadImage(a)
        }, 130);
        BackgroundLazyload.hasEvent || (WIN.addEventListener("scroll", function() {
            clearTimeout(BackgroundLazyload.time);
            BackgroundLazyload.time = setTimeout(function() {
                BackgroundLazyload.lazyLoadImage()
            }, 100)
        }, !1), BackgroundLazyload.hasEvent = !0)
    },
    lazyLoadImage: function(a, c) {
        var b = document.querySelectorAll(".lazy_bg"),
            e, d = b.length;
        for (e = 0; e < d; e++) a && "all" == a ? BackgroundLazyload.imageReplace(b[e]) : BackgroundLazyload.imageVisiable(b[e])
    },
    imageVisiable: function(a) {
        var c = a.getBoundingClientRect();
        (0 < c.top && 0 < 2 * WIN.innerHeight - c.top || 0 >= c.top && 0 <= c.bottom) && BackgroundLazyload.imageReplace(a)
    },
    imageReplace: function(a) {
        if (a) {
            a = $(a);
            var c = a.attr("data-url");
            c && (a.css("background-image", "url(" + c + ")"), a.removeAttr("data-url"), a.removeClass("lazy_bg"))
        }
    }
};
var SlideBanner = {
    hasPrototype: !1,
    IsAndroid: /Android|HTC/i.test(UA) || !! (WIN.navigator.platform + "").match(/Linux/i),
    createNew: function(a) {
        a = a || {};
        this.hasPrototype || (this.init.prototype = SlideBanner, this.hasPrototype = !0);
        return new this.init(a)
    },
    init: function(a) {
        var c = this;

        this.dom = document.getElementById("slider");
        if(!this.dom)
            return;
        this.parentDom = this.dom.parentNode;
        this.childrens = this.dom.children;
        this.bannerCount = this.childrens.length;
        this.curPage = a.curPage || 1;
        this.boxWidth = document.body.clientWidth;
        this.boxHeight = this.parentDom.clientHeight;
        this.startPos = {
            x: 0,
            y: 0
        };
        this.moveDes = {
            x: 0,
            y: 0
        };
        this.autoTime = null;
        this.intervalTime = a.intervalTime || 5E3;
        this.transformSpeed = a.transformSpeed || "0.6s";
        this.auto = !0;
        "undefined" != typeof a.auto && !1 === a.auto && (this.auto = !1);
        this.needTab = !0;
        "undefined" != typeof a.needTab && !1 === a.needTab && (this.needTab = !1);
        this.tabBox = a.tabBox || void 0;
        this.tabItemHtml = a.tabItemHtml || "<i></i>";
        this.tabCurrentClass = a.tabCurrentClass || "cur";
        1 < this.bannerCount && (this.formated || this.formatDom(), this.bindEvent(), this.auto && setTimeout(function() {
            c.autoRun()
        }, this.intervalTime - 2E3))
    },
    formatDom: function() {
        var a = this.childrens[0].cloneNode(),
            c = this.childrens[this.bannerCount - 1].cloneNode();
        a.innerHTML = this.childrens[0].innerHTML;
        c.innerHTML = this.childrens[this.bannerCount - 1].innerHTML;
        this.dom.appendChild(a);
        this.dom.insertBefore(c, this.childrens[0]);
        if (this.needTab) {
            this.tabBox || (this.tabBox = document.createElement("div"), this.tabBox.className = "slide_tab", this.parentDom.appendChild(this.tabBox));
            a = "";
            for (c = 0; c < this.bannerCount; c++) a += this.tabItemHtml;
            this.tabBox.innerHTML = a;
            this.tabItems = this.tabBox.children
        }
        this.setSize();
        this.toPage();
        this.formated = !0
    },
    setSize: function() {
        for (var a = 0, c = this.childrens.length; a < c; a++) this.childrens[a].style.width = this.boxWidth + "px", this.childrens[a].style.height = this.boxHeight + "px";
        this.dom.style.width = this.boxWidth * this.childrens.length + "px";
        this.dom.style.height = this.boxHeight + "px"
    },
    autoRun: function() {
        var a = this;
        if (!this.auto) return !1;
        clearTimeout(this.autoTime);
        this.autoTime = null;
        this.autoTime = setTimeout(function() {
            a.curPage++;
            a.adjustTranslate();
            a.toPageAnimation();
            clearTimeout(a.autoTime);
            a.autoRun()
        }, this.intervalTime)
    },
    bindEvent: function() {
        var a = this,
            c = function(b) {
                1 < a.bannerCount && a.touchend.call(this, b, a)
            };
        a.dom.addEventListener("touchstart", function(b) {
            a.touchstart.call(this, b, a)
        }, !1);
        a.dom.addEventListener("touchmove", function(b) {
            1 < a.bannerCount && a.touchmove.call(this, b, a)
        }, !1);
        a.dom.addEventListener("touchend", c, !1);
        a.dom.addEventListener("touchcancel", c, !1);
        a.dom.addEventListener("webkitTransitionEnd", function() {
            a.isScrolling = void 0
        }, !1);
        window.addEventListener("resize", function() {
            a.resize()
        }, !1);
        this.auto && this.IsAndroid && (window.addEventListener("focus", function() {
            a.autoRun()
        }, !1), window.addEventListener("blur", function() {
            clearTimeout(a.autoTime)
        }, !1))
    },
    touchstart: function(a, c) {
        clearTimeout(c.autoTime);
        c.autoTime = null;
        c.startPos.x = a.targetTouches[0].pageX;
        c.startPos.y = a.targetTouches[0].pageY;
        c.moveDes.x = c.moveDes.y = 0;
        c.dom.style.webkitTransition = "0s"
    },
    touchmove: function(a, c) {
        c.moveDes.x = a.targetTouches[0].pageX - c.startPos.x;
        c.moveDes.y = a.targetTouches[0].pageY - c.startPos.y;
        var b = c.getTranslate();
        "undefined" == typeof c.isScrolling && (c.isScrolling = !! (c.isScrolling || Math.abs(c.moveDes.x) < Math.abs(c.moveDes.y)));
        !0 != c.isScrolling && (a.preventDefault(), c.dom.style.webkitTransition = "0s", c.dom.style.webkitTransform = "translate3d(" + (b + c.moveDes.x) + "px, 0,0)")
    },
    touchend: function(a, c) {
        c.isScrolling = void 0;
        40 < Math.abs(c.moveDes.x) && (0 > c.moveDes.x ? c.curPage++ : c.curPage--);
        c.adjustTranslate(c.moveDes.x);
        c.toPageAnimation();
        c.auto && c.autoRun()
    },
    resize: function() {
        clearTimeout(this.autoTime);
        this.boxWidth = document.body.clientWidth;
        this.boxHeight = this.parentDom.clientHeight;
        this.setSize();
        this.toPage();
        this.auto && this.autoRun()
    },
    getTranslate: function() {
        return -(this.boxWidth * this.curPage)
    },
    setTranslate: function(a) {
        this.dom.style.webkitTransition = "0";
        this.dom.style.webkitTransform = "translate3d(" + a + "px, 0,0)"
    },
    adjustTranslate: function(a) {
        a = a || 0;
        this.curPage > this.bannerCount ? (this.curPage = 1, this.setTranslate(a)) : 1 > this.curPage && (this.curPage = this.bannerCount, this.setTranslate(-(this.boxWidth * (this.bannerCount + 1)) + a))
    },
    toPage: function() {
        var a = this.getTranslate();
        this.setTranslate(a);
        this.needTab && this.setTab();
        this.lazyImg()
    },
    toPageAnimation: function() {
        var a = this.getTranslate(this),
            c = this;
        setTimeout(function() {
            c.dom.style.webkitTransitionDuration = c.transformSpeed;
            c.dom.style.webkitTransform = "translate3d(" + a + "px, 0,0)"
        }, 10);
        this.needTab && this.setTab();
        this.lazyImg()
    },
    setTab: function() {
        for (var a = this.curPage - 1, c = 0; c < this.tabItems.length; c++) this.tabItems[c].className = this.tabItems[c].className.replace(this.tabCurrentClass, ""), c == a && (this.tabItems[c].className = this.tabItems[c].className + " " + this.tabCurrentClass)
    },
    lazyInt: !1,
    lazyLoaded: !1,
    lazyImg: function() {
        if (!this.lazyLoaded) {
            var a = this.curPage,
                c = [];
            !this.lazyInt && 1 == a ? (c.push(this.childrens[0].querySelector("img.banner_lazy")), c.push(this.childrens[a].querySelector("img.banner_lazy")), c.push(this.childrens[a + 1].querySelector("img.banner_lazy")), c.push(this.childrens[this.bannerCount + 1].querySelector("img.banner_lazy")), c.push(this.childrens[this.bannerCount].querySelector("img.banner_lazy"))) : (c.push(this.childrens[a + 1].querySelector("img.banner_lazy")), c.push(this.childrens[a - 1].querySelector("img.banner_lazy")));
            if (0 < c.length)
                for (var a = 0, b = c.length; a < b; a++) c[a] && c[a].hasAttribute("data-url") && (c[a].src = c[a].getAttribute("data-url"), c[a].removeAttribute("data-url"), c[a].className = c[a].className.replace(/banner_lazy/g, "").trim());
            0 == this.dom.querySelectorAll("img.banner_lazy").length && (this.lazyLoaded = !0)
        }
    }
};

Public = {
    init: function() {
        /LieBaoFast/i.test(UA) && (window.scrollTo(0, 1), window.scrollTo(0, 0));
        IsIOS && $("body").addClass("ios");
        ImageLazyload.init();
        BackgroundLazyload.init();

        Public.pub();
        Public.backTop();

        SlideBanner.createNew({

            tabBox: document.getElementById("slide_page")
        })
        $("#r_share").on("click", function(a) {
            //Client.share();

            a.preventDefault();
            return !1
        });
        Public.showPannel()
        if (/LieBaoFast/i.test(UA)) {
            var a = Public.getLBFastVer();
            2E4 <= a || ($("body").addClass("lbfast_old"), $(".menu_pannel").html('<li><a href="/" class="ico_list_home" w="nav" stat="15797">\u9996\u9875</a><a href="/category.php?cat_id=2&amp;title=\u7535\u89c6\u5267&amp;type=recommend" class="ico_list_tv" w="nav" stat="15799">\u7535\u89c6\u5267</a><a href="/category.php?cat_id=4&amp;title=\u7efc\u827a" class="ico_list_drama" w="nav" stat="15801">\u7efc\u827a</a></li><li><a href="/category.php?cat_id=3&amp;title=\u52a8\u6f2b" class="ico_list_comic" w="nav" stat="15800">\u52a8\u6f2b</a><a href="/news.php" class="ico_list_news" w="nav" stat="18925">\u70ed\u70b9</a><a href="/rank.php?title=\u699c\u5355" class="ico_list_rank" w="nav" stat="15802">\u699c\u5355</a><span></span></li>'));
            23200 <= a ? 0 < $("#detail_page").length ? Client.loadAd(1) : Client.loadAd(0) : Public.gdtAd()
        } else{};
        setTimeout(function() {
            0 < $("#top_down").length && (!/LieBao/i.test(UA) && !/LBKIT/i.test(UA)) && Public.showAd()
        }, 500);

    },
    getLBFastVer: function() {
        if (/LieBaoFast/i.test(UA)) {
            var a = UA.match(/liebaofast\/([\d]+\.[\d]+\.[\d]+)/i);
            2 == a.length && (a = a[1]);
            var c = a.split("."),
                a = parseInt(c[0]),
                c = parseInt(c[1]);
            return 1E4 * a + 100 * c
        }
        return 0
    },
    pub: function() {

    },
    backTop: function() {
        var a = $("#r_side,#to_top");
        0 != a.length && (WIN.addEventListener("scroll", function() {
            getScrollTop() > WIN.innerHeight ? a.css("display", "block") : a.css("display", "none")
        }, !1), a.on("click", function() {
            window.scrollTo(0, 0)
        }))
    },
    showPannel: function(a) {
        $(".ico_filter").click(function(){
            if($(".condition").hasClass('show_condition'))
            {
                $(".condition").removeClass("show_condition");
            }
            else
            {
                $(".condition").addClass("show_condition");
            }
        })
        $(".sel_cate").click(function(){
            $(".menu_pannel").toggle();
        })

    },
    hidePannel: function() {
        $(".trans_layer").css("display", "none");
        $(".menu_pannel").parent().removeClass("show_pannel")
    },
    adShowed: !1,
    showAd: function() {

    },
    gdtAd: function() {

    }
};
Detail = {
    fromnative: !1,
    changeCover: function () {
        var a = DOC.createElement("div"),
            c;
        a.style.webkitFilter = "blur(16px)";
        DOC.getElementsByTagName("body")[0].insertBefore(a, DOC.getElementsByTagName("body")[0].firstElementChild);
        c = WIN.getComputedStyle(a, null);
        if (!c.webkitFilter || !("" != c.webkitFilter && "none" != c.webkitFilter) || IsIOS) $(".detail_info_box .detail_bg").remove(), $(".detail_info_box").addClass("detail_noblur");
        $(a).remove()
    },
    init: function () {


            Detail.changeCover();

            IsAndroid || $("body").addClass("ios");
            "" == $(".detail_collection .addtext").html() && $(".detail_collection .addtext").css("display", "none");
            $("#cache_list .cache_episode").attr("id", "cache_episode");
            $("#head_tab").html($("#main_tab").html());

//            WeiXin.shareTitle = "\u6211\u6b63\u5728\u770b\u300a" + Detail.title + "\u300b\u3002\u7528\u730e\u8c79\u5fae\u4fe1\u8ffd\u5267\uff0c\u770b\u5927\u7247\u53c8\u5feb\u53c8\u723d~";
//            Client.iosShareConfig.description = "\u6211\u6b63\u5728\u770b\u300a" + Detail.title + "\u300b\u3002\u5b9e\u65f6\u8ffd\u5267\uff0c\u6700\u65b0\u5f71\u89c6\u5267\u4e0d\u9519\u8fc7\uff01";
//            Client.iosShareConfig.img_url = WeiXin.shareImgUrl = $(".detail_cover img").attr("src");
//            7 >= (Math.round((new Date).getTime() / 1E3) - Detail.vtime) / 86400 && (Detail.update = !0);

            $("#main_tab a,#head_tab a").removeClass("cur");
            $("#main_tab a").eq(0).addClass("cur");
            $("#head_tab a").eq(0).addClass("cur");
            $("#main_tab a,#head_tab a").on("click", function () {
                if (!$(this).hasClass("cur")) {
                    WIN.scrollTo(0, $("#" + $(this).attr("data-type")).offset().top - $(".fixed_head").height() - 38);
                    var a = $(this).attr("data-type");
                    setTimeout(function () {
                        $("#main_tab a,#head_tab a").removeClass("cur");
                        for (var c = 0; c < $("#main_tab a,#head_tab a").length; c++) $("#main_tab a,#head_tab a").eq(c).attr("data-type") == a && $("#main_tab a,#head_tab a").eq(c).addClass("cur")
                    }, 50)
                }
            });
            $("#client_play").on("click", function (a) {
                var c = $(this).attr("data-chapter"),
                    d = $(this).attr("href"),
                    f = $("#change_source").attr("data-provider"),
                    g = Detail.providers[f].providerName || "",
                    k = Client.globalData,
                    l = 0;
                k && (k.last_play_chapter && k.play_list && k.play_list[k.last_play_chapter]) && (l = k.play_list[k.last_play_chapter].played_time);
                DetailStat.stat("link", Detail.tsid, encodeURIComponent(g));
                if ("sh" != f && "qy" != f && "dy" != f && "ls" != f)
                    if (Client.newApi && "undefined" != typeof Client.isLeibaoFast && Client.isLeibaoFast && 1 < Client.apiVersion) {
                        if ("qt" != f) return Client.play(Detail.tsid, c, d, Detail.title, l), a.preventDefault(), !1
                    } else if (Client.newApi && Client.globalData) {
                        if ("1" == Detail.type && Client.globalData && Client.globalData.download_list && Client.globalData.download_list["0"] && Client.globalData.download_list["0"].download_finish) return d = Detail.providers[Detail.provider].url, Client.play(0, 0, d, Detail.title, l), a.preventDefault(), !1;
                        if (Client.globalData && Client.globalData.download_list && Client.globalData.download_list[c] && Client.globalData.download_list[c].download_finish) return Client.play(Detail.tsid, c, "", Detail.title, l), a.preventDefault(), !1
                    }
                setTimeout(function () {
                    -1 == d.indexOf("acfun.tv") ? WIN.location.href = d : WIN.location.href = "http://v.duba.com/url.html?u=" + encodeURIComponent(d)
                }, 100);
                a.preventDefault();
                return !1
            });
            if (0 < $(".detail_introduction").length) $(".detail_introduction").on("click", function () {
                $(this).toggleClass("detail_introduction_open");
                $(this).hasClass("detail_introduction_open") && DetailStat.stat("cont", Detail.tsid, "\u7b80\u4ecb")
            });
            $("#key_director a").on("click", function (a) {
                var c = $(this).attr("href");
                DetailStat.stat("cont", Detail.tsid, "\u5bfc\u6f14");
                setTimeout(function () {
                    WIN.location.href = c
                }, 100);
                a.preventDefault()
            });
            $("#key_director a").on("click", function (a) {
                var c = $(this).attr("href");
                DetailStat.stat("cont", Detail.tsid, "\u4e3b\u6f14");
                setTimeout(function () {
                    WIN.location.href = c
                }, 100);
                a.preventDefault()
            });
            if (0 < $("#last_chapter a").length) $("#last_chapter a").on("click", function (a) {
                var c = $(this).attr("href"),
                    d = $(this).attr("data-chapter"),
                    f = Detail.title,
                    g = $(this).parent().index($("#last_chapter li")) + 1,
                    k = $("#change_source").attr("data-provider"),
                    l = Detail.providers[k].providerName || "";
                DetailStat.stat("last_chapter", g, Detail.tsid);
                DetailStat.stat("link", Detail.tsid, encodeURIComponent(l));
                if (Client.newApi && "qy" != k && "dy" != k && "ls" != k)
                    if (Client.newApi && "undefined" != typeof Client.isLeibaoFast && Client.isLeibaoFast && 1 < Client.apiVersion) Client.play(Detail.tsid, d, c, Detail.title);
                    else if ($(this).hasClass("epsd_downloaded")) return Client.play(Detail.tsid, d, "", f), a.preventDefault(), !1;
                setTimeout(function () {
                    -1 == c.indexOf("acfun.tv") ? WIN.location.href = c : WIN.location.href = "http://v.duba.com/url.html?u=" + encodeURIComponent(c)
                }, 100);
                a.preventDefault()
            });
            if (1 < $("#source_list li").length && ("1" == Detail.type || "2" == Detail.type)) $("#change_source .video_source").addClass("video_source_more"), $("#change_source").on("click", function () {
                Detail.showLayer();
                $("#source_list").css("display", "block");
                $("#source_list").height() > 0.8 * WIN.innerHeight && $("#source_list").css("height", 0.8 * WIN.innerHeight)
            }), $("#source_list li").on("click", function () {
                if (!$(this).hasClass("cur")) {
                    var a = $(this).attr("data-provider");
                    $("#change_source .video_source").html('<i class="source_iocn source_' + Detail.providers[a].icon + '"></i>' + Detail.providers[a].providerName);
                    $("#change_source").attr("data-provider", a);
                    $("#source_list li").removeClass("cur");
                    $(this).addClass("cur");
                    "1" == Detail.type ? $("#client_play").attr("href", Detail.providers[a].url) : Detail.getProvider($("#d_list .episode_list a").attr("data-chapter"));
                    if (0 < $("#client_download").length && 1 < Client.apiVersion && (1 != Detail.type || IsAndroid)) "qt" == a ? $("#client_download").css("display", "none") : $("#client_download").css("display", "inline-block");
                    0 < $(".qqapp_adbox").length && $(".qqapp_adbox").remove();
                    DetailStat.stat("cont", Detail.tsid, "\u6362\u6e90")
                }
                Detail.hideLayer()
            });
            //Detail.splitTabEvent();
//            WIN.addEventListener("scroll", function (a) {
//                Detail.changeTab()
//            }, !1);
//            DOC.addEventListener("touchmove", function (a) {
//                Detail.changeTab()
//            }, !1);
//            WIN.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", Detail.winResize, !1);



    },
    splitTabEvent: function() {
        $(".detail_more_tabs a").on("click", function() {
            $(".detail_more_tabs a").removeClass("cur");
            $(this).addClass("cur");
            Detail.getPage()
        })
    },
    changeTab: function() {
        var a = $("#main_tab").offset().top,
            c = WIN.scrollY + $(".fixed_head").height();
        c >= a ? $("#head_tab").css("display", "-webkit-box") : $("#head_tab").css("display", "none");
        for (a = $("#main_tab a").length - 1; - 1 < a; a--)
            if ($("#" + $("#main_tab a").eq(a).attr("data-type")).offset().top - 38 - 40 <= c) {
                $("#main_tab a,#head_tab a").removeClass("cur");
                $("#main_tab a").eq(a).addClass("cur");
                $("#head_tab a").eq(a).addClass("cur");
                break
            } - 1 == a && ($("#main_tab a,#head_tab a").removeClass("cur"), $("#main_tab a").eq(0).addClass("cur"), $("#head_tab a").eq(0).addClass("cur"))
    }
}



